package com.xxhui.guidepagedemo.ViewPage;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.View;

import java.util.HashMap;
import java.util.LinkedHashMap;

/**
 * Created by Administrator on 2016/8/7.
 */
public class StackViewPage extends ViewPager {

    private float align_to_left_pixels;

    private HashMap<Integer, View> pageMap = new LinkedHashMap<Integer, View>();//一个有序的map

    private View leftPage;

    private View rightPage;

    public StackViewPage(Context context) {
        super(context);
    }

    public StackViewPage(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onPageScrolled(int position, float offset, int offsetPixels) {

        leftPage = pageMap.get(position);

        if(leftPage!=null){
            leftPage.bringToFront();
        }
        rightPage = pageMap.get(position+1);

        if(rightPage!=null){
            align_to_left_pixels = -getWidth() - getPageMargin() +offsetPixels;
            rightPage.setTranslationX(align_to_left_pixels);
        }
        super.onPageScrolled(position, offset, offsetPixels);
    }

    public void updatePageMap(Integer position, View v) {
        this.pageMap.put(position,v);
    }
}
